var oper = getQueryString('oper')
var sysId = getQueryString('id')
$(function () {
  $('#oper').val(oper)
  if (oper === 'edit' || oper === 'view') {
    getDetail(sysId)
    $('#code').attr('disabled', true)
  }

  jQuery.validator.addMethod("format",function(value,element){
    var account = /^[a-zA-Z0-9_]*$/;
    return account.test(value);
  },"请输入数字、字母、下划线");

  jQuery.validator.addMethod("codeRemote", function (value, element) {
    var result;
    $.ajax({
      url: api + '/comm/outsystem/checkCode',
      data: JSON.stringify({outSysCode: value}),
      async: false,
      headers:{
        'Content-Type': 'application/json;charset=UTF-8',
      },
      type: 'post',
      success: function (res) {
        result = !Boolean(res.data[0])
      }
    });
    return result
  }, "接出项目编码已存在");

  $.common.initFormInfo();
});



$("#editForm").validate({
  onkeyup: false,
  rules: {
    name: {
      required: true
    },
    code: {
      required: true,
      format: true,
      codeRemote: true
    },
  },
  messages: {
    name: {
      required: "请输入项目名称"
    },
    code: {
      required: "请输入项目编码",
      codeRemote: '接出项目编码已存在'
    },
  },
  focusCleanup: true
});


function getDetail(id) {
  $.operate.get(api + '/comm/outsystem/' + id, function (res) {
    res.data.oper = oper
    applyDrawing('#editForm', res.data)
    if (res.data.dsType == 1 && res.data.dsScope) {
    }
    $.common.initFormInfo();
  }, false)
}

function submitHandler() {
  if ($.validate.form()) {
    $.common.ajaxCommitForm($('#editForm'), false);
    return false;
  }
}